import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: () => import('../views/Home.vue'),
    children: [
      {
        path: '/personList',
        component: () => import('../views/person/PersonList.vue'),
      },
      {
        path: '/categoryList',
        component: () => import('../views/category/CategoryList.vue'),
      },
      {
        path: '/addCategory',
        component: () => import('../views/category/AddCategory.vue'),
      },
      {
        path: '/personJournalismList',
        component: () => import('../views/person/PersonJournalismList.vue'),
      },
      {
        path: '/interviewList',
        component: () => import('../views/interview/InterviewList.vue'),
      },
      {
        path: '/interviewAdd',
        component: () => import('../views/interview/InterviewAdd.vue'),
      }
    ]
  },
  {
    path: '/login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

/**全局前置导航守卫 */

// router.beforeEach((form,to,next) =>{
//   let token = sessionStorage.getItem("token");
//   console.info(token)
//   if(form.path=='/login'){
//     return next();
//   }
//   if(token==undefined){
//     console.info("空的token");
//     return router.push("/login");
//   }
//   //放行
//   next();
// })

export default router
